from sqlalchemy import Column, String, Boolean, Numeric, func, DateTime

from database import db


class Currency(db.Model):
    id = Column(String(40), primary_key=True)
    screen_name = Column(String(100))
    type = Column(String(20), default='normal')
    logo = Column(String(300))
    rate = Column(Numeric(precision=15,scale=4), default=0.00)
    automatic_update = Column(Boolean(), default=True)
    updated_at = Column(DateTime(), default=func.now())
    prefix = Column(String(10), default='')
    suffix = Column(String(10), default='')

    TYPE_MAIN = 'main'
    def is_main_currency(self):
        return self.type == 'main'

    def transform_amount(self, amount):
        return amount * self.rate
